package cool.taomu.toolkit.logo

import javax.inject.Inject
import javax.ws.rs.GET
import javax.ws.rs.Path
import org.apache.commons.vfs2.FileSystemManager
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import org.apache.commons.io.IOUtils
import javax.ws.rs.core.Response

@Path("logo")
class LogoController {

    @Inject
    FileSystemManager fsm;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    def Response logo() {
        try(var fobj = fsm.resolveFile("res://logo.txt")) {
            if (fobj.exists) {
                var logoStr = IOUtils.toString(fobj.content.inputStream, "UTF-8")
                return Response.ok(logoStr).build
            }
        }
        return Response.status(404).build
    }
}
